{include /common/header}
<script>
    var M={};
    $(function() {
        M.del = function(id){
            if (confirm('确定删除吗？')) {
                $.ajax({
                    url: '{:\mylib\Route::buildUrl('/admin/model/del')}',
                    type: 'POST',
                    dataType: 'json',
                    data: {
                        id:id
                    },
                    success:function(res){
                        if (res.code) {
                            location.reload();
                        }else{
                            alert(res.message);
                        }
                    }
                });
            }
        }
    });
</script>
<div class="title">模型管理</div>
<p>
    <a href="{:\mylib\Route::buildUrl('/admin/model/add')}" class="btn btn-primary">添加模型</a>
</p>
<div class="table-responsive">
    <table class="table table-bordered table-striped">
        <thead>
            <tr>
                <th>#</th>
                <th>名称</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            {foreach $models as $v}
            <tr>
                <td>{$v.id}</td>
                <td>{$v.title}</td>
                <td>
                    <a href="{:\mylib\Route::buildUrl('/admin/model/edit')}?id={$v.id}">编辑</a>
                    <a href="#" onclick="M.del('{$v.id}')">删除</a>
                    <a href="{:\mylib\Route::buildUrl('/admin/field/index')}?model_id={$v.id}">字段管理</a>
                </td>
            </tr>
            {/foreach}
        </tbody>
    </table>
</div>
{include /common/footer}